//
//  ChatMessageCell.m
//  ForestPack
//
//  Created by jimmy on 2018/7/23.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "ChatMessageCell.h"
#import "Masonry.h"

@interface ChatMessageCell ()

@property (nonatomic, strong) UIImageView *headImageView;
@property (nonatomic, strong) UILabel     *titleLabel;
@property (nonatomic, strong) UILabel     *detailLabel;
@property (nonatomic, strong) UILabel     *timeLabel;

@end

@implementation ChatMessageCell

+ (ChatMessageCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"ChatMessageCell";
    ChatMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ChatMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;    
}

- (void)createSubView
{
    self.headImageView = [[UIImageView alloc] init];
    self.headImageView.image = [UIImage imageNamed:@"结构设计"];
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = 31;
    [self addSubview:self.headImageView];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@15);
        make.left.equalTo(@13);
        make.width.equalTo(@62);
        make.height.equalTo(@62);
    }];
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.textColor = REXADECIMALCOLOR(@"#333333");
    self.titleLabel.font = Kfont(14);
    self.titleLabel.text = @"森林头条";
    self.detailLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@20);
        make.left.equalTo(self.headImageView.mas_right).offset(10);
        make.width.equalTo(@((SCREEN_WIDTH - 85)/2 * 1.3));
        make.height.equalTo(@15);
    }];
    
    self.detailLabel = [[UILabel alloc] init];
    self.detailLabel.textColor = REXADECIMALCOLOR(@"#666666");
    self.detailLabel.font = Kfont(12);
    self.detailLabel.numberOfLines = 0;
    self.detailLabel.text = @"消息消息消息消息消息消息消息消息消息消息消息消息消息消息消息消息消息";
    self.detailLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:self.detailLabel];
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
        make.left.equalTo(self.headImageView.mas_right).offset(10);
        make.width.equalTo(@(SCREEN_WIDTH - 85));
        make.height.equalTo(@40);
    }];
    
    self.timeLabel = [[UILabel alloc] init];
    self.timeLabel.textColor = REXADECIMALCOLOR(@"#666666");
    self.timeLabel.font = Kfont(12);
    self.timeLabel.textAlignment = NSTextAlignmentRight;
    self.timeLabel.text = @"2018.05.25";
    [self addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(20);
        make.right.equalTo(self.mas_right).offset(-10);
        make.width.equalTo(@((SCREEN_WIDTH - 85)/2 * 0.7));
        make.height.equalTo(@15);
    }];
    
    UIImageView *lineImageV = [[UIImageView alloc] init];
    lineImageV.image = [UIImage imageNamed:@"虚线"];
    [self addSubview:lineImageV];
    [lineImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_bottom).offset(-1);
        make.left.equalTo(self.mas_left).offset(13);
        make.width.equalTo(@(SCREEN_WIDTH - 26));
        make.height.equalTo(@1);
    }];
}

@end
